﻿using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Text.Json;
using System.Net;

namespace Dotnet.Performance.Test.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            var socketsHandler = new SocketsHttpHandler
            {
                PooledConnectionLifetime = TimeSpan.FromSeconds(60),
                PooledConnectionIdleTimeout = TimeSpan.FromMinutes(20),
            };
            //HttpMessageHandler messageHandler = 
            var http = new HttpClient(socketsHandler)
            {
                DefaultRequestVersion = HttpVersion.Version20,
                BaseAddress = new Uri("http://localhost:5000/hello"),
            };
            http.DefaultRequestHeaders.Clear();
            http.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
            http.DefaultRequestHeaders.Add("Keep-Alive", "600");
            http.DefaultRequestHeaders.Add("Content-Type", "application/json");

            while (true)
            {
                Task.Run(async () =>
                {
                    var res = await http.GetAsync("/",HttpCompletionOption.ResponseHeadersRead);
                    var data = JsonSerializer.SerializeToUtf8Bytes(res.Content);
                    Console.WriteLine(data);
                });
                Task.Delay(100);
            }
        }
    }
}
